<% if @saved -%>
  TracksPages.page_inform("<%=@status_message%>");
  add_recurring_todo_to_active_container();
  replace_form_with_empty_form();
  $( "#new-recurring-todo" ).dialog( "close" );
  TracksPages.set_page_badge(<%= @down_count %>);
<% else -%>
  TracksPages.show_errors(html_for_error_messages());
<% end -%>

function replace_form_with_empty_form() {
  $('div.recurring_container').html(html_for_empty_form());
}

function add_recurring_todo_to_active_container() {
  $('#recurring_todos_container').append(html_for_recurring_todo());
  $('#<%= dom_id(@recurring_todo)%>').effect('highlight', {}, 2000 );
  $('#recurring-todos-empty-nd').hide();
}

function html_for_recurring_todo() {
  return "<%= @saved ? js_render(@recurring_todo) : "" %>";
}

function html_for_empty_form() {
  return "<%= @saved ? js_render('recurring_todo_form') : "" %>";
}

function html_for_error_messages() {
  return "<%= js_error_messages_for(@recurring_todo) %>";
}